/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package nite.gestures;

import com.primesense.NITE.DirectionVelocityAngleEventArgs;
import com.primesense.NITE.SwipeDetector;
import com.primesense.NITE.VelocityAngleEventArgs;
import java.util.logging.Level;
import java.util.logging.Logger;
import nite.gestures.AbstractGesture.PrimaryPointUpdateObserver;
import org.OpenNI.GeneralException;
import org.OpenNI.IObservable;
import org.OpenNI.IObserver;

/**
 *
 * @author xvanek9
 */
public class SwipeGesture  {
    
    PrimaryPointUpdateObserver obs;

    public PrimaryPointUpdateObserver getObs() {
        return obs;
    }

    public void setObs(PrimaryPointUpdateObserver obs) {
        this.obs = obs;
    }
    
    public SwipeDetector init(){
        SwipeDetector sd = null;
        try {
            sd = new SwipeDetector();
            sd.getSwipeDownEvent().addObserver(new SwipeDownObserver());
            sd.getSwipeUpEvent().addObserver(new SwipeUpObserver());
            sd.getSwipeRightEvent().addObserver(new SwipeRightObserver());
            sd.getSwipeLeftEvent().addObserver(new SwipeLeftObserver());
//            obs = new PrimaryPointUpdateObserver();
//            sd.getPrimaryPointUpdateEvent().addObserver(obs);
        } catch (GeneralException ex) {
            Logger.getLogger(SwipeGesture.class.getName()).log(Level.SEVERE, null, ex);
        }
        return sd;
    }
    
//    private class GeneralSwipeObserver implements IObserver <DirectionVelocityAngleEventArgs>{
//
//        @Override
//        public void update(IObservable<DirectionVelocityAngleEventArgs> io, DirectionVelocityAngleEventArgs args) {
//            System.out.println("You swope " + args.getDirection().name());
//        }
//    }
    
    private class SwipeDownObserver implements IObserver <VelocityAngleEventArgs>{

        @Override
        public void update(IObservable<VelocityAngleEventArgs> io, VelocityAngleEventArgs args) {
            System.out.println("Swiped down, velocity: " + args.getVelocity() + ", angle: " + args.getAngle());
        }
    }
    
    private class SwipeUpObserver implements IObserver <VelocityAngleEventArgs>{

        @Override
        public void update(IObservable<VelocityAngleEventArgs> io, VelocityAngleEventArgs args) {
            System.out.println("Swiped up, velocity: " + args.getVelocity() + ", angle: " + args.getAngle());
        }
    }
        
    private class SwipeRightObserver implements IObserver <VelocityAngleEventArgs>{

        @Override
        public void update(IObservable<VelocityAngleEventArgs> io, VelocityAngleEventArgs args) {
            System.out.println("Swiped right, velocity: " + args.getVelocity() + ", angle: " + args.getAngle());
        }
    }
            
    private class SwipeLeftObserver implements IObserver <VelocityAngleEventArgs>{

        @Override
        public void update(IObservable<VelocityAngleEventArgs> io, VelocityAngleEventArgs args) {
            System.out.println("Swiped left, velocity: " + args.getVelocity() + ", angle: " + args.getAngle());
        }
    }
}
